{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/css/layui.css">
<style>
.progress{display:none;}
.notice{color:red;font-size:12px;margin-left:10px;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据更新</h5>
                </div>
                <div class="ibox-content">
				
					<form action="" id="form" class="layui-form" method="post">
						<span class="notice">注意：此页面的操作可能会耗时较长，如遇到更新失败或中断，请重新操作！</span>
						<table class="layui-table mag0">
							<colgroup>
								<col width="25%">
								<col width="45%">
								<col>
							</colgroup>
							<thead>
							<tr>
								<th>更新内容</th>
								<th>操作</th>
							</tr>
							</thead>
							<tr>
								<td>专业</td>
								<td>
									<a class="layui-btn major">更新接口数据</a>
									<a class="layui-btn major_column">更新数据结构</a><span class="notice">注意：更新接口数据后，请务必更新数据结构！</span>
								</td>
							</tr>
							<tr>
								<td>院校</td> 
								<td>
									<a class="layui-btn school">更新接口数据</a>
									<a class="layui-btn school_column">更新数据结构</a><span class="notice">注意：更新接口数据后，请务必更新数据结构！</span>
								</td>
							</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
						<div style="text-align:center;" class="progress">准备中...</div>
					</form>

                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>
<script type="text/javascript">
   
    $(function(){
		$(".major_column").click(function(){
			layer.msg('功能禁用', {icon:5,time: 1500});
			return false;
			
			layer.confirm('确定要更新吗？',{icon:3, title:'提示信息'},function(index){
				var index = layer.msg('执行中，请稍后', {icon: 16, time: false, shade: 0.8});
				$.post("{:url('major_column')}",{},function(data){
					
					if(data.code == 1){
						layer.msg(data.msg, {icon: 1, time: 1500}, function () {
							
						 });
					}else{
						layer.msg(data.msg, {icon: 2, time: 1500}, function () {
						
						});
						return false;
					}
				})
			});
        })
		$(".school_column").click(function(){
			layer.msg('功能禁用', {icon:5,time: 1500});
			return false;
			
			layer.confirm('确定要更新吗？',{icon:3, title:'提示信息'},function(index){
				var index = layer.msg('执行中，请稍后', {icon: 16, time: false, shade: 0.8});
				$.post("{:url('school_column')}",{},function(data){
					
					if(data.code == 1){
						layer.msg(data.msg, {icon: 1, time: 1500}, function () {
							
						 });
					}else{
						layer.msg(data.msg, {icon: 2, time: 1500}, function () {
						
						});
						return false;
					}
				})
			});
        })
		
		var index_open;
        $(".major").click(function(){
			layer.msg('功能禁用', {icon:5,time: 1500});
			return false;
			
			$(".progress").html('');
			var page = 1;
            var index_confirm = layer.confirm('更新会覆盖原有数据,确定要更新吗？',{icon:3, title:'提示信息'},function(index){
				index_open = layer.open({type: 1,title: '正在更新',area: ['300px', '100px'],closeBtn:false,fix: false, maxmin: false,content: $(".progress")})
				layer.close(index_confirm);
				data_update('major',page);
				
			});
        })
        $(".school").click(function(){
			layer.msg('功能禁用', {icon:5,time: 1500});
			return false;
			
			$(".progress").html('');
			var page = 1;
            var index_confirm = layer.confirm('请确保先更新专业再做此操作，更新会覆盖原有数据,确定要更新吗？',{icon:3, title:'提示信息'},function(index){
				index_open = layer.open({type: 1,title: '正在更新',area: ['300px', '100px'],closeBtn:false,fix: false, maxmin: false,content: $(".progress")})
				layer.close(index_confirm);
				data_update('school',page);
			});
        })
		function data_update(type,page){
			$.post("{:url('data_update')}",{type:type,page:page},function(data){
				
				if(data.code){
					var return_data = data.data;
					if(return_data.is_end==0){
						//index_msg = layer.msg('更新中，'+page+'/'+return_data.page_total, {icon: 16, time: false, shade: 0.8});
						$(".progress").html('更新中：'+page+'/'+return_data.page_total);
						page = page+1;
						data_update(type,page)
					}else{
						layer.close(index_open);
						layer.msg('更新完成', {icon:6,time: 1500});
						return false;
					}
				}else{
					layer.close(index_open);
					layer.msg('更新中断，请重新操作', {icon:5,time: 1500});
					return false;
				}
				
			})
		}
     
    });

</script>
</body>
</html>
